//
//  PictureTableViewCell.m
//  UI_Project_A
//
//  Created by dllo on 16/1/28.
//  Copyright © 2016年 GH. All rights reserved.
//

#import "PictureTableViewCell.h"
#import "PictureModel.h"
#import <UIImageView+WebCache.h>
#import <DKNightVersion.h>

@interface PictureTableViewCell ()


@property (nonatomic ,retain)UILabel *label;

@property (nonatomic ,retain)UIImageView *imageViewPic;

@end

@implementation PictureTableViewCell


- (void)dealloc {

    [_label release];
    [_imageViewPic release];
    [super dealloc];
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {


    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        [self createLabel];
        [self createimage];
    }

    return self;
}




- (void)createLabel {

    self.label = [[UILabel alloc] init];
    [self.contentView addSubview:self.label];
    [self.label release];
    self.label.numberOfLines = 0;
    self.label.textAlignment = 1;

    self.label.dk_textColorPicker = DKColorWithColors([UIColor colorWithWhite:0.247 alpha:1.000],[UIColor whiteColor]);

}




- (void)passModelWithPic:(PictureModel *)model {



    self.label.text = model.title;
    if (model.imageurls.count == 1) {
       NSString *str = [self Substring:[model.imageurls[0] objectForKey:@"url"]];
    
        [self.imageViewPic sd_setImageWithURL:[NSURL URLWithString:str]];
        
    }


}

#pragma mark - 图片Url截取
- (NSString *)Substring:(NSString *)urlString {
    
    
    NSString *sub = urlString;
    
    if ([sub isEqualToString:@""]) {
        return nil;
    }
    
    
    if ([sub hasSuffix:@"jpg"]) {
        return urlString;
    }
    else {
        
        NSRange range = [urlString rangeOfString:@"u="];
        
        NSString *sub1 = [urlString substringFromIndex:range.location+2];
        
        NSRange lastRange = [sub1 rangeOfString:@"&"];
        sub = [sub1 substringToIndex:lastRange.location];
        
    }
    
    return sub;
}






- (void)createimage {

    self.imageViewPic = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@""]];
    [self.contentView addSubview:self.imageViewPic];
    [self.imageViewPic release];
}




- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.label.frame = CGRectMake(10, 10, self.frame.size.width - 20, 40);
    self.imageViewPic.frame = CGRectMake(10, 60, self.frame.size.width - 20,self.frame.size.height - 65);



}






- (void)awakeFromNib {
    // Initialization code
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
